namespace SolidMvvm {
	using System;
	using System.Globalization;
	using System.Windows.Data;

	/// <summary>
	///     A parameter of true means "reverse the hex string".
	/// </summary>
	[ValueConversion(typeof(byte[]), typeof(string))]
	public class ByteArrayToHexStringConverter : IValueConverter {
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			var isReversed = parameter != null && (bool)parameter;
			return value == null ? string.Empty : (isReversed ? Conversions.ByteArrayToHexString(Conversions.GetNewReversedArray((byte[])value)) : Conversions.ByteArrayToHexString((byte[])value));
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
			var isReversed = parameter != null && (bool)parameter;
			return value == null ? null : (isReversed ? Conversions.GetNewReversedArray(Conversions.HexStringToByteArray((string)value)) : Conversions.HexStringToByteArray((string)value));
		}
	}
}
